package com.tamecode.chapter05.part13;

import com.tamecode.chapter05.part11.sub1.LogonService;
import com.tamecode.chapter05.part11.sub1.UserDao;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * 测试代码注入 UserServiceFactoryBean
 */
public class UserServiceFactoryBeanTest {

    public static void main(String[] args) {
//        ApplicationContext ctx = new AnnotationConfigApplicationContext(UserServiceFactoryBean.class);
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
        ctx.register(UserDao.class); // 方便 UserServiceFactoryBean 中注入使用
        ctx.addBeanFactoryPostProcessor(new UserServiceFactoryBean());
        ctx.refresh();

        LogonService logonService = ctx.getBean("logonService", LogonService.class);
        logonService.getUserDao().info(); // user dao.

        LogonService logonService2 = ctx.getBean("logonService2", LogonService.class);
        System.out.println(logonService2.getUserDao()); // null

    }


}
